/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sjava_ptest.ui;

import sjava_ptest.bussiness.ColumnData;
import java.util.ArrayList;
import javax.swing.JLabel;
import javax.swing.table.AbstractTableModel;
import sjava_ptest.bussiness.Branch;

/**
 *
 * @author Kim Dinh Chien
 */
public class ModelShow extends AbstractTableModel {

    private ArrayList<Branch> arr;

    public ModelShow(ArrayList<Branch> arr) {
        this.arr = arr;
    }
    public static final ColumnData col[] = {
        new ColumnData("Branch_ID", 10, JLabel.RIGHT),
        new ColumnData("Branch_Name", 50, JLabel.LEFT),
        new ColumnData("Branch_Address", 50, JLabel.LEFT),
        new ColumnData("Branch_City", 50, JLabel.LEFT),
        new ColumnData("Branch_Phone", 15, JLabel.RIGHT)
    };

    public ArrayList<Branch> getArr() {
        return arr;
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return true;
    }

    public void setArr(ArrayList<Branch> arr) {
        this.arr = arr;
    }

    public int getRowCount() {
        return arr.size();
    }

    public int getColumnCount() {
        return col.length;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Branch b = arr.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return b.getBranch_ID();
            case 1:
                return b.getBranch_Name();
            case 2:
                return b.getBranch_Address();
            case 3:
                return b.getBranch_City();
            case 4:
                return b.getBranch_Phone();
        }
        return null;
    }
}
